package com.example.springboot1.utils;

import org.apache.commons.codec.digest.DigestUtils;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class BusinessUtils {




    public static final String symbol = "~`@#\\%\\&<>\"',;_\\-\\^\\$\\.\\*\\+\\?\\=!:|\\{\\}\\(\\)\\[\\]/\\\\";
    public static final String PWD_1 = "^(?!\\d+$)(?![a-z]+$)(?![A-Z]+$)(?![" + symbol + "]+$)\\S{8,32}$";
    public static final String PWD_2 = "^(?![A-Za-z]+$)(?![A-Z0-9]+$)(?![a-z0-9]+$)(?![ A-Z" + symbol + "]+$)(?![ a-z" + symbol + "]+$)(?![ 0-9" + symbol + "]+$)\\S{8,32}$";
    public static final String PWD_3 = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[ ~`@#\\%\\&<>\"',;_\\-\\^\\$\\.\\*\\+\\?\\=!:|\\{\\}\\(\\)\\[\\]/\\\\])\\S{8,32}$";

    public static int getPwdLevel(String pwd) {
        if (pwd == null || pwd.isEmpty()) {
            return 0;
        }
        if (pwd.matches(PWD_3)) {
            return 3;
        }
        if (pwd.matches(PWD_2)) {
            return 2;
        }
        if (pwd.matches(PWD_1)) {
            return 1;
        }
        return 0;
    }

    public static String getDefaultPwd() {
        Stream<Character> pwdStream = Stream.concat(RandomChartUtil.getRandomNumbers(1),
                Stream.concat(RandomChartUtil.getRandomSpecialChars(1),
                Stream.concat(RandomChartUtil.getRandomRange(4, 33, 122),
                        Stream.concat(RandomChartUtil.getRandomAlphabets(1, true), RandomChartUtil.getRandomAlphabets(1, false)))));
        List<Character> charList = pwdStream.collect(Collectors.toList());
        Collections.shuffle(charList);
        return charList.stream()
                .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append)
                .toString();
    }


    private static Double findCalcData(Double[] calcDataArray, int idx) {
        if (calcDataArray == null || calcDataArray.length <= idx) {
            return null;
        }
        return calcDataArray[idx];
    }

    public static void main(String[] args) {
//        String salt = RandomStringUtils.random(20, true, true);
        String salt = "BqoKYXkVQtaADQ8N5Idr";
        String defaultPwd = BusinessUtils.getDefaultPwd();
//        System.out.println(defaultPwd);
//        System.out.println(salt);
        String data="0=p%DBL9dcjd";
        String s1 = DigestUtils.md5Hex(data);
//        String salt="wT3@3M'm";
        String s = DigestUtils.md5Hex(s1 + salt);
//        System.out.println(s);
        int i = new BigDecimal("2001").compareTo(new BigDecimal("2000"));
        System.out.println(i);

    }
}
